package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicCarrierLine;
import cn.stylefeng.guns.modular.basic.mapper.BasicCarrierLineMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicCarrierLineParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicCarrierLineResult;
import  cn.stylefeng.guns.modular.basic.service.BasicCarrierLineService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 承运商线路关联表 服务实现类
 * </p>
 *
 * @author like
 * @since 2024-10-10
 */
@Service
public class BasicCarrierLineServiceImpl extends ServiceImpl<BasicCarrierLineMapper, BasicCarrierLine> implements BasicCarrierLineService {

    @Override
    public void add(BasicCarrierLineParam param){
        BasicCarrierLine entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicCarrierLineParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicCarrierLineParam param){
        BasicCarrierLine oldEntity = getOldEntity(param);
        BasicCarrierLine newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicCarrierLineResult findBySpec(BasicCarrierLineParam param){
        return null;
    }

    @Override
    public List<BasicCarrierLineResult> findListBySpec(BasicCarrierLineParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicCarrierLineParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicCarrierLineParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicCarrierLine getOldEntity(BasicCarrierLineParam param) {
        return this.getById(getKey(param));
    }

    private BasicCarrierLine getEntity(BasicCarrierLineParam param) {
        BasicCarrierLine entity = new BasicCarrierLine();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
